package Interface_sort;

//对比泛型接口 Comparable<T>
//实现了对比泛型接口的类，可以对该类集合使用排序
//接口的用途，可以用来扩展类功能
public class Employee implements Comparable<Employee> {

    private String name;
    private double salary;

    public Employee(String name,double salary){
        this.name = name;
        this.salary = salary;

    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public void raiseSalary(double byPercent){
        salary += salary*byPercent/100;
        // salary = salary*(1+byPercent/100);
    }

    public int compareTo(Employee o) {
        //直接调用了 Double 的比较方法，也是返回整形值
        return Double.compare(salary,o.salary)*-1;
        /*int result = 0;
        if (this.salary > o.salary)
        {
            result = 1;
        }
        else if(this.salary<o.salary)
        {
            result = -1;
        }
        else {
            result = 0;
        }
        return result;*/

    }
}
